package com.jdwx.opengl.kotlin

import android.icu.text.Transliterator
import android.util.Log

interface Named {
    val name: String
}

interface Person : Named {
    val firstName: String
    val lastName: String

    override val name: String get() = "$firstName $lastName"
}

data class Employee(
        // 不必实现“name”
        override val firstName: String,
        override val lastName: String
        //val position: Transliterator.Position
) : Person


interface A {
    fun foo() { print("A") }
    fun bar()
}

interface B {
    fun foo() { print("B") }
    fun bar() { print("bar") }
}

class C : A {
    override fun bar() { print("bar") }
}

class D : A, B {
    override fun foo() {
        super<A>.foo()
        super<B>.foo()
    }

    override fun bar() {
        super<B>.bar()
    }
}

fun main(){

    var employee = Employee("bai","jinhao")

    println( employee.firstName )
    println( employee.name )


    var d = D()

    println( d.bar() )
    println( d.foo() )

    data class User (var id:Int,var name:String)

    var user = User(0,"zhaoyanjun")

    println( "zhaoyanjun:"+"toString $user"+user.id )

    var user1 = User(0,"zhaoyanjun")
    var user2 = user1.copy(id = 2)

    println( "zhaoyanjun:"+"toString $user1 $user2" )

    val baz = 6    // 相同模块内可见

//    fun MutableList<Int>.swap(index1: Int, index2: Int) {
//        val tmp = this[index1] // “this”对应该列表
//        this[index1] = this[index2]
//        this[index2] = tmp
//    }
    fun <T> MutableList<T>.swap(index1: Int, index2: Int) {
        val tmp = this[index1] // “this”对应该列表
        this[index1] = this[index2]
        println("扩展")
        this[index2] = tmp
    }

    val list = mutableListOf(1, 2, 3)
    list.swap(0, 2) // “swap()”内部的“this”会保存“list”的值
    println( list[0] )


    open class Shape

    class Rectangle: Shape()

    fun Shape.getName() = "Shape"

    fun Rectangle.getName() = "Rectangle"

    fun printClassName(s: Shape) {
        println(s.getName())
    }

    printClassName(Rectangle())
    printClassName(Shape())


    class Example{
        fun printFunctionType(){
            println("printFunctionType")
        }
    }

    fun Example.printFunctionType(i: Int){
        println("printFunctionType1")
    }

    Example().printFunctionType(2)


    fun Any?.toString(): String {
        if (this == null) return "null"
        // 空检测之后，“this”会自动转换为非空类型，所以下面的 toString()
        // 解析为 Any 类的成员函数
        return toString()
    }
    data class User1(val name: String = "", val age: Int = 0)
    val (name, age) = User1("baijinhao",100)

    println( "name:"+name +",age:"+age )






}
